package com.blue.firecat.vo;

import com.blue.firecat.contants.Contants;
import com.blue.firecat.enums.TradeStatusEnum;
import com.blue.firecat.utils.CharUtil;
import com.blue.firecat.utils.date.DateUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.time.LocalDate;
import java.util.Date;

/**
 * @描述 交易vo对象
 * @时间 2017/6/24 20:43
 * @作者 肖亦鸣
 */
public class TradeVo {
    private Long tradeId;
    private String tradeIds;
    private Long orderId;
    private Long userId;
    private Integer gameId;
    private String gameName;
    private Integer orderType;
    private Integer tradeStatus;
    private Integer tradeStatusSelect;
    private String tradeStatusString;
    private String pics;
    private String isError;
    private String remark;
    private Integer agree;

    private String datemin = LocalDate.now().minusMonths(1).toString() + " 00:00:00";
    private String datemax = LocalDate.now().plusMonths(1).toString() + " 00:00:00";

    private Date dateMin = DateUtil.getDateByString(LocalDate.now().minusMonths(1).toString() + " 00:00:00");
    private Date dateMax = DateUtil.getDateByString(LocalDate.now().plusMonths(1).toString() + " 00:00:00");

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public Long getTradeId() {
        return tradeId;
    }

    public void setTradeId(Long tradeId) {
        this.tradeId = tradeId;
    }

    public Integer getGameId() {
        return gameId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Integer getOrderType() {
        return orderType;
    }

    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
    }

    public Integer getTradeStatus() {
        return tradeStatus;
    }

    public void setTradeStatus(Integer tradeStatus) {
        this.tradeStatus = tradeStatus;
    }

    public Integer getTradeStatusSelect() {
        return tradeStatusSelect;
    }

    public String getTradeIds() {
        return tradeIds;
    }

    public void setTradeIds(String tradeIds) {
        this.tradeIds = tradeIds;
    }

    public void setTradeStatusSelect(Integer tradeStatusSelect) {
        this.tradeStatusSelect = tradeStatusSelect;
    }

    public String getDatemin() {
        return datemin;
    }

    public void setDatemin(String datemin) {
        this.datemin = datemin;
        if (StringUtils.isEmpty(datemin)) {
            this.setDateMin(DateUtil.getDateByString(Contants.DATE_MIN));
        } else {
            this.setDateMin(DateUtil.getDateByString(datemin));
        }
    }

    public String getDatemax() {
        return datemax;
    }

    public void setDatemax(String datemax) {
        this.datemax = datemax;
        if (StringUtils.isEmpty(datemax)) {
            this.setDateMax(DateUtil.getDateByString(Contants.DATE_MAX));
        } else {
            this.setDateMax(DateUtil.getDateByString(datemax));
        }
    }

    public Date getDateMin() {
        if (dateMin == null) {
            this.setDateMin(DateUtil.getDateByString(Contants.DATE_MIN));
        }
        return dateMin;
    }

    public void setDateMin(Date dateMin) {
        this.dateMin = dateMin;
    }

    public Date getDateMax() {
        if (dateMin == null) {
            this.setDateMax(DateUtil.getDateByString(Contants.DATE_MAX));
        }
        return dateMax;
    }

    public void setDateMax(Date dateMax) {
        this.dateMax = dateMax;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Long getOrderId() {
        return orderId;
    }

    public String getPics() {
        return pics;
    }

    public void setPics(String pics) {
        this.pics = pics;
    }

    public String getIsError() {
        return isError;
    }

    public void setIsError(String isError) {
        this.isError = isError;
    }

    public Integer getAgree() {
        return agree;
    }

    public void setAgree(Integer agree) {
        this.agree = agree;
    }

    public void setGameId(Integer gameId) {
        if (gameId == -1) {
            return;
        }
        this.gameId = gameId;
        Contants.TRADE_GAME_RESULT.getData().stream().filter(game -> gameId.equals(game.getId())).forEach(game -> {
            this.setGameName(game.getName());
        });
    }

    public void setGameName(String gameName) {
        this.gameName = gameName;
    }

    public String getGameName() {
        return gameName;
    }

    public String getTradeStatusString() {
        return tradeStatusString;
    }

    public void setTradeStatusString(String tradeStatusString) {
        if(!CharUtil.isChinese(tradeStatusString)){
            try {
                tradeStatusString = new String(tradeStatusString.getBytes("ISO-8859-1"), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        this.setTradeStatus(TradeStatusEnum.getCodeByValue(tradeStatusString));
        this.tradeStatusString = tradeStatusString;
    }
}
